"""
债券数据采集定时任务
"""

from celery import shared_task
import logging
from src.data_collector.bond_collector import BondCollector

logger = logging.getLogger(__name__)

@shared_task(bind=True, name="collect_bond_basic_info")
def collect_bond_basic_info(self):
    """定时采集债券基本信息"""
    try:
        collector = BondCollector()
        result = collector.collect_bond_list()
        return {
            "status": "success",
            "result": result
        }
    except Exception as e:
        logger.error(f"债券基本信息采集失败: {str(e)}")
        return {
            "status": "error",
            "error": str(e)
        }

@shared_task(bind=True, name="collect_bond_daily_data")
def collect_bond_daily_data(self, bond_code: str):
    """定时采集债券日行情数据"""
    try:
        collector = BondCollector()
        count = collector.collect_daily_quote(bond_code)
        return {
            "status": "success",
            "count": count
        }
    except Exception as e:
        logger.error(f"债券行情数据采集失败: {str(e)}")
        return {
            "status": "error",
            "error": str(e)
        }